from pydantic import AnyHttpUrl, IPvAnyAddress
from pydantic_settings import BaseSettings
from typing import Union
from urllib.parse import quote_plus


class Config(BaseSettings):

    ALGORITHM: str = "HS256"

    ACCESS_TOKEN_EXPIRE_MINUTES: int = 120
    REFRESH_TOKEN_EXPIRE_MINUTES: int = 1

    SECRET_KEY: str = "bd5ab949af96ed73b7033f7b38ea13f618b07ae1d724121f085ceffde2affec4"

    # 配置Mysql环境
    # MYSQL_USERNAME: str = 'root'
    # MYSQL_PASSWORD: str = "Ycaqkj"
    # MYSQL_HOST: Union[AnyHttpUrl, IPvAnyAddress] = "127.0.0.1"
    # MYSQL_PORT: str = '3306'
    # MYSQL_DATABASE: str = 'yckj_db'

    # Mysql地址
    # SQLALCHEMY_DATABASE_URI = f"mysql+pymysql://{MYSQL_USERNAME}:{quote_plus(MYSQL_PASSWORD)}@" \
    #                           f"{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DATABASE}"
    # SQLALCHEMY_DATABASE_URI: str = f"mysql+pymysql://{MYSQL_USERNAME}:{MYSQL_PASSWORD}@" \
    #                           f"{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DATABASE}"


    # 配置PgSql环境
    PGSQL_USERNAME: str = 'postgres'
    PGSQL_PASSWORD: str = "Ycaqkj"
    PGSQL_HOST: Union[AnyHttpUrl, IPvAnyAddress] = "127.0.0.1"
    PGSQL_PORT: str = '5432'
    PGSQL_DATABASE: str = 'yckj_db'
    
    SQLALCHEMY_DATABASE_URI: str = f"postgresql://{PGSQL_USERNAME}:{PGSQL_PASSWORD}@" \
                                f"{PGSQL_HOST}:{PGSQL_PORT}/{PGSQL_DATABASE}"
    
config = Config()
